package com.voute.View.Activity;

import android.content.Intent;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.voute.App.App;
import com.voute.Base.BaseActivity;
import com.voute.R;


/**
 * 修改个人信息中的个人姓名以及签名信息的画面
 * Created by liucxu on 2017/1/22.
 */

public class ModifyUserNameSignatureActivity extends BaseActivity {

    private RelativeLayout back_layout;
    private TextView title;
    private TextView publish_tv;
    private EditText user_name_edt;
    private TextView reaining_tv;
    private boolean edit_user_name = true;

    @Override
    public int getLayoutId() {
        return R.layout.activity_modify_user_info;
    }

    @Override
    public void setupView() {
        back_layout = $(R.id.back_layout);
        title = $(R.id.title);
        publish_tv = $(R.id.publish_tv);
        user_name_edt = $(R.id.user_name_edt);
        reaining_tv = $(R.id.reaining_tv);
        back_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ModifyUserNameSignatureActivity.this.finish();
            }
        });
        Intent intent = getIntent();
        edit_user_name = intent.getBooleanExtra("edit_user_name", true);
        if (edit_user_name) {
            user_name_edt.setHint("请输入你的昵称");
            title.setText("昵称");
        } else {
            user_name_edt.setHint("输入您的签名");
            title.setText("个性签名");
            user_name_edt.setText(intent.getStringExtra("user_signature"));
            reaining_tv.setText(user_name_edt.getText().toString().length()+"/100");
            user_name_edt.setSelection(user_name_edt.getText().length());
        }
        user_name_edt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                reaining_tv.setText(editable.toString().length() + "/100");
            }
        });

        publish_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(user_name_edt.getText().toString())) {
                    App.GetInstance().finishActivity(ModifyUserNameSignatureActivity.this);
                }
                else{
                    Intent intent = new Intent();
                    intent.putExtra("modify_value", user_name_edt.getText().toString());
                    setResult(0x05,intent);
                    App.GetInstance().finishActivity(ModifyUserNameSignatureActivity.this);
                }
            }
        });
    }

    @Override
    public void setupData() {

    }
}
